package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.School;
import io.geekidea.springbootplus.system.mapper.SchoolMapper;
import io.geekidea.springbootplus.system.service.SchoolService;
import io.geekidea.springbootplus.system.param.SchoolPageParam;
import io.geekidea.springbootplus.system.vo.SchoolQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-23
 */
@Slf4j
@Service
public class SchoolServiceImpl extends BaseServiceImpl<SchoolMapper, School> implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSchool(School school) throws Exception {
        return super.save(school);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSchool(School school) throws Exception {
        return super.updateById(school);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSchool(Long id) throws Exception {
        return super.removeById(id);
    }


    @Override
    public List<School> getAllList(LambdaQueryWrapper<School> wrapper) throws Exception{
        return schoolMapper.selectList(wrapper);
    }



    @Override
    public SchoolQueryVo getSchoolById(Serializable id) throws Exception {
    return schoolMapper.getSchoolById(id);
    }

    @Override
    public Paging<SchoolQueryVo> getSchoolPageList(SchoolPageParam schoolPageParam) throws Exception {
        Page<SchoolQueryVo> page = new PageInfo<>(schoolPageParam, OrderItem.desc(getLambdaColumn(School::getCreateTime)));
        IPage<SchoolQueryVo> iPage = schoolMapper.getSchoolPageList(page, schoolPageParam);
        return new Paging<SchoolQueryVo>(iPage);
    }

}
